﻿using System;
using Nofs.Net.nofs.metadata.interfaces;
using biz.ritter.javapi.lang;

namespace Nofs.Net.AnnotationDriver
{
    public class Factory : IMetadataFactory
    {
        private INoFSClassLoader _loader = null;
        private IMethodFilter _filter = null;
        private IAttributeAccessor _accessor = null;

        //@Override
        public IAttributeAccessor CreateAttributeAccessor() //throws Exception 
        {
            if (_accessor == null)
            {
                if (_loader == null)
                {
                    _accessor = new AttributeAccessor();
                }
                else
                {
                    _accessor = new AttributeAccessor(_loader);
                }
            }
            return _accessor;
        }

        //@Override
        public INoFSClassLoader CreateClassLoader(String fileName) //throws Exception 
        {
            if (_loader == null)
            {
                _loader = new NoFSClassLoader(fileName);
            }
            return _loader;
        }

        //@Override
        public IMethodFilter CreateMethodFilter()
        {
            if (_filter == null)
            {
                _filter = new MethodFilter();
            }
            return _filter;
        }

        //@Override
        public INoFSClassLoader CreateClassLoader(ClassLoader loader) //throws Exception 
        {
            if (_loader == null)
            {
                _loader = new NoFSClassLoader(loader);
            }
            return _loader;
        }
    }
}
